﻿/*
 * 王洪涛 4月19日
 */

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text.RegularExpressions;
using EnvironmentManagerSystem.MODE;
using EnvironmentManagerSystem.BLL;

namespace EnvironmentManagerSystem.UserManager
{
    public partial class UserRole : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (StfInfo.ReSession()) return;if (!IsPostBack)
            {
                labUserName.Text ="用户：" +Request.QueryString["UserName"];
                BindRoleList();
            }
        }

        protected void BindRoleList()
        {
            cblistRole.DataSource = Role.GetList();
            cblistRole.DataTextField = "RoleName";
            cblistRole.DataValueField = "ID";
            cblistRole.DataBind();

            string[] RoleIDs = EnvironmentManagerSystem.BLL.User.GetRoleID(Convert.ToInt32(Request.QueryString["ID"])).Split(',');
            foreach (string RoleId in RoleIDs)
            {
                if (RoleId.Trim() != string.Empty)
                    cblistRole.Items.FindByText(RoleId).Selected = true;
            }
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            string RoleIDs = string.Empty;
            foreach(ListItem item in cblistRole.Items)
            {
                if (item.Selected == true)
                    RoleIDs += item.Text + ',';
            }
            RoleIDs = RoleIDs.TrimEnd(',');
            if (EnvironmentManagerSystem.BLL.User.UpdateRole(RoleIDs,int.Parse(Request.QueryString["ID"])))
                Jscript.Alert("权限修改成功！", this);
            else
                Jscript.Alert("权限修改失败！", this);
        }

        #region 按钮(取消)(x)
        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Write("<script>window.parent.art.dialog.list['用户角色管理'].close();</script>");
        }
        #endregion
        
    }
}
